package main

import (
	"fmt"
	"strings"
)

func main() {
	// 变量
	var peopleName string
	var peopleAge int
	var peopleSex string
	peopleAge = 12
	peopleName = "limian"
	peopleSex = "female"
	fmt.Println(peopleName)
	fmt.Println(peopleAge)
	fmt.Println(peopleSex)
	// 字符串操作
	fmt.Println(strings.Split(peopleName, "m"))
	fmt.Println(strings.Contains(peopleName, "mian"))
	// 转换字符串
	name := "BBB"
	nameTemp := []rune(name)
	nameTemp[0] = 'A'
	fmt.Println(string(nameTemp))

	// 常量
	const (
		_       = iota
		KB      = 1 << (10 * iota)
		MB      = 1 << (10 * iota)
		GB      = 1 << (10 * iota)
		TB      = 1 << (10 * iota)
		math    = 100
		engilsh = 200
		chinese = 300
	)
	fmt.Println(KB)
	fmt.Println(MB)
	fmt.Println(GB)
	fmt.Println(TB)
	fmt.Println(math)
	fmt.Println(engilsh)
	fmt.Println(chinese)

	// if条件控制
	if peopleAge > 18 {
		fmt.Println("青年人")
	} else {
		fmt.Println("少年人")
	}

	// for循环控制
	for i := 0; i < 10; i++ {
		fmt.Println(i)
	}

	// 数组
	work := [3]int{4, 5, 6}
	for i, v := range work {
		fmt.Println(i)
		fmt.Println(v)
	}

	// 切片
	var sliceTemp []int
	var sliceTemp1 = make([]int, 3, 5)
	sliceTemp = []int{1, 2, 3}
	fmt.Println(sliceTemp)
	fmt.Println(sliceTemp[1:2])
	fmt.Println(append(sliceTemp, 4, 5))
	copy(sliceTemp1, sliceTemp)
	fmt.Println(sliceTemp1)

	// map
	var dict map[string]int
	dict = make(map[string]int, 10)
	dict["名字"] = 12
	dict["年龄"] = 18
	fmt.Println(dict["名字"])

	fmt.Println(add(1, 2))

}


func add(x int, y int) int {
	return x + y
}
